function [beta] = opt_beta(dn, SolarTime, latt)

[zenith, azimuth] = sun_positionST(dn, SolarTime, latt);

alpha = 90 - zenith;

y = cosd(alpha)*sind(azimuth);
x = cosd(alpha)*cosd(azimuth);
z = sind(azimuth);

b = atand(y/(((x^2)+(z^2))^(1/2)));
b = real(b);
b = b - 0.0001;
if b <= 0 
    beta = 0;
else
    beta = b;
end
